feat(api): add a std::pmr::memory_resource adapter (PoolMemoryResource)#113
Merged
Conversation
PoolMemoryResource binds one Pool behind the runtime std::pmr::memory_resource interface, so a single resource can back any std::pmr container via std::pmr::polymorphic_allocator without the per-type PoolAllocator<T> rebind — the "door left open" in ADR-0018. Deterministic (bytes, alignment) routing to the bound pool: fitting requests come from the pool (throwing std::bad_alloc on exhaustion, never falling back, so deallocate routing stays deterministic); over-sized / over-aligned requests delegate to a configurable upstream resource (get_default_resource() by default). is_equal compares (pool, upstream) identity. The whole facility is gated behind PBR_MEMORY_POOL_HAS_PMR (a __cpp_lib_memory_resource feature-test) so the header is a harmless no-op where std::pmr is unavailable. Header-only and purely additive: the frozen C ABI and the existing C++ types are unchanged, so this is a SemVer MINOR. It opens roadmap Milestone 9 (post-1.0 ergonomics, hardening & tooling; ADR-0037). - ADR-0042 records the decision (+ ADR index row). - Dedicated doctest (pool_memory_resource), gated like the header. - Spec §5.2 lists the type; §7 maps it to ADR-0042; §7.1 un-defers it. - ROADMAP Milestone 9 created with this as item 9.1. - Doxyfile predefines __cpp_lib_memory_resource so the gated class is documented on the API site. - CHANGELOG [Unreleased] Added entry. The README milestone-table row and the patterns-catalogue refinement are deferred to the v1.2.0 release PR to keep this feature PR off the translated docs surface (they would trip the i18n-freshness gate). Validated locally: MSVC build + doctest (5 cases / 33 assertions), clang-format and clang-tidy clean, consistency lint OK. Closes #107 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The link resolved to docs/adr/doxygen/Doxyfile (from the ADR directory) and tripped the Lychee internal-link check; correct it to ../doxygen/Doxyfile. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
it::d4np::memorypool::PoolMemoryResource, astd::pmr::memory_resourceAdapter thatbinds one
Poolbehind the runtimestd::pmrinterface — so a single resource can backany
std::pmrcontainer (viastd::pmr::polymorphic_allocator) without the per-typePoolAllocator<T>rebind. This is the "door left open" in ADR-0018. Header-only and purelyadditive — the frozen C ABI and the existing C++ types are unchanged, so this is a SemVer
MINOR (
v1.2.0candidate). It opens roadmap Milestone 9.Motivation
PoolAllocator<T>(ADR-0018) bakes the pool into a container's type;std::pmrchooses thestorage policy at run time by handing a container a
memory_resource*. ADR-0018 recorded thepmrresource as deferred, not rejected. Issue #107 / Milestone 9 opens it.Changes
pool_memory_resource.hpp—PoolMemoryResource : public std::pmr::memory_resource. Anon-owning back-reference to a
Poolplus a configurable upstream resource. Deterministic(bytes, alignment)routing (mirroring ADR-0018 §2): fitting requests come from the pool(throwing
std::bad_allocon exhaustion — never falling back, sodo_deallocateroutesdeterministically); over-sized / over-aligned requests go upstream
(
std::pmr::get_default_resource()by default).do_is_equalby(pool, upstream)identity.Gated behind
PBR_MEMORY_POOL_HAS_PMR(a__cpp_lib_memory_resourcefeature-test) so theheader is a no-op where
<memory_resource>is unavailable.configurable upstream, availability gate) and the rejected alternatives; ADR index row added.
pool_memory_resource_test— gated like the header; proves pool routing +exhaustion + reissue, upstream routing (via
null_memory_resource),is_equal, and anend-to-end
std::pmr::list/std::pmr::vector/polymorphic_allocatorround-trip.__cpp_lib_memory_resourceso the gated class appears on the API site.[Unreleased]Added entry.Design Patterns
pool to the runtime
std::pmr::memory_resourceinterface. No new pattern is introduced.Verification
pool_memory_resourcedoctest 5 cases / 33 assertions pass.clang-format(22.x) clean;clang-tidyclean on the header + test (the(bytes, alignment)bugprone-easily-swappable-parametersfindings are the fixedstd::pmroverride signature —suppressed with rationale).
python tools/consistency_lint.py→ OK.test matrix; no threading added).
Documentation Impact
[Unreleased]entry.featlabel,v1.2.0milestone.v1.2.0release PR (to keep this feature PR off the translated docssurface — editing them trips the
i18n-freshnessgate): theREADME.mdMilestone-9 table row(a release-time refresh per M8.8) and the
docs/patterns/README.mdAdapter-row refinement (theAdapter pattern is already catalogued; the pmr application is fully documented in ADR-0042 and
the spec §7 map). The release PR refreshes both and re-syncs the
zh-Hans/jatranslationsin one pass. The spec rows remain
stale(already flagged since docs(spec): reconcile the memory-pool spec with the as-built system #110/docs(spec): add a C4 component diagram and record Mermaid as the diagram tooling #112).Closes #107.